#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e6 + 5;

int n, m;
int a[N];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  deque<int> dq;
  int j = 1;
  rep(i, 1, n) {
    int l = max(1, i - m), r = i - 1;
    while (j <= r) {
      while (dq.size() && a[dq.back()] >= a[j]) dq.pop_back();
      dq.push_back(j++);
    }
    while (dq.size() && dq.front() < l) dq.pop_front();
    if (dq.size())
      cout << a[dq.front()] << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}